# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import pandas as pd
import numpy as np

unsorted_df = pd.DataFrame(
    np.random.randn(10, 2),
    index=[1, 4, 6, 2, 3, 5, 9, 8, 0, 7],
    columns=['col2', 'col1'])
print(unsorted_df)
print(unsorted_df.sort_index(ascending=False))
print(unsorted_df.sort_index(axis=1))


# 按照某个字段进行排序

d = {'Name': pd.Series(['Tom', 'James', 'Ricky', 'Vin', 'Steve', 'Minsu', 'Jack',
                        'Lee', 'David', 'Gasper', 'Betina', 'Andres']),
     'Age': pd.Series([25, 26, 25, 23, 30, 29, 23, 34, 40, 30, 51, 46]),
     'Rating': pd.Series([4.23, 3.24, 3.98, 2.56, 3.20, 4.6, 3.8, 3.78, 2.98, 4.80, 4.10, 3.65])}
unsorted_df = pd.DataFrame(d)
print('----\n', unsorted_df)
sort_age = unsorted_df.sort_values(
    by='Rating', ascending=False)
print('----\n', sort_age)
sort_age_rating = unsorted_df.sort_values(
    by=['Age', 'Rating'],
    ascending=[True, False])
print('----\n', sort_age_rating)
